package com.itqf.configration;

import com.itqf.relam.UserRelam;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 作者:高少东
 * 项目名:  product_gsd
 * 时间: 2019/12/19 9:53
 * 描述:
 */

@Configuration
public class ShiroConfig {


    @Bean
    public DefaultWebSecurityManager securityManager(UserRelam relam){

         DefaultWebSecurityManager webSecurityManager = new DefaultWebSecurityManager();

         webSecurityManager.setRealm(relam);

         return  webSecurityManager;
    }


    @Bean
    public DefaultShiroFilterChainDefinition  chainDefinition(){

        DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();

        chainDefinition.addPathDefinition("/logout","logout");
        chainDefinition.addPathDefinition("/","authc");
        chainDefinition.addPathDefinition("/passwordPage","authc");
        chainDefinition.addPathDefinition("/indexPage","authc");

        chainDefinition.addPathDefinition("/productPage","authc");
        chainDefinition.addPathDefinition("/productAddPage","authc");
        chainDefinition.addPathDefinition("/productUpdatePage","authc");

        chainDefinition.addPathDefinition("/orderFromPage","authc");
        chainDefinition.addPathDefinition("/orderFromAddPage","authc");
        chainDefinition.addPathDefinition("/orderFromUpdatePage","authc");


        chainDefinition.addPathDefinition("/gongyingPage","authc");
        chainDefinition.addPathDefinition("/gongyingAddPage","authc");
        chainDefinition.addPathDefinition("/gongyingUpdatePage","authc");

        chainDefinition.addPathDefinition("/yuangongPage","authc");
        chainDefinition.addPathDefinition("/yuangongAddPage","authc");
        chainDefinition.addPathDefinition("/yuangongUpdatePage","authc");


        chainDefinition.addPathDefinition("/yuangongPage","roles[经理]");
        chainDefinition.addPathDefinition("/yuangongAddPage","perms[修改]");
        chainDefinition.addPathDefinition("/yuangongUpdatePage","roles[经理]");


        chainDefinition.addPathDefinition("/**","anon");

        return  chainDefinition;
    }

}
